# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=openrct2
pkgver=0.2.6
_pkgver_objects=1.0.14
_pkgver_title_sequences=0.1.2
pkgrel=1
pkgdesc="Open-source re-implementation of Roller Coaster Tycoon 2"
arch="all !s390x !mips !mips64" # Build fails on s390x
url="https://openrct2.io"
license="GPL-3.0-only"
depends="$pkgname-data"
makedepends="cmake ninja jansson-dev libzip-dev libpng-dev speexdsp-dev fontconfig-dev curl-dev icu-dev sdl2-dev mesa-dev fts-dev unzip"
install="$pkgname.post-install"
source="https://github.com/openrct2/openrct2/archive/v$pkgver/openrct2-v$pkgver.tar.gz
	$pkgname-$pkgver-title_sequences.zip::https://github.com/OpenRCT2/title-sequences/releases/download/v$_pkgver_title_sequences/title-sequence-v$_pkgver_title_sequences.zip
	$pkgname-$pkgver-objects.zip::https://github.com/OpenRCT2/objects/releases/download/v$_pkgver_objects/objects.zip"
subpackages="$pkgname-static $pkgname-doc $pkgname-cli $pkgname-data::noarch"
# net required for downloading googletests
# TODO: pre-download googletest and integrate
options="net"
builddir="$srcdir/OpenRCT2-$pkgver"

prepare() {
	default_prepare

	mkdir title object
	unzip "$srcdir"/$pkgname-$pkgver-title_sequences.zip -d title
	unzip "$srcdir"/$pkgname-$pkgver-objects.zip -d object
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DWITH_TESTS=ON \
		-DDOWNLOAD_TITLE_SEQUENCES=OFF \
		-DDOWNLOAD_OBJECTS=OFF
	ninja -C build
}

package() {
	DESTDIR="$pkgdir" ninja -C build install

	install -d "$pkgdir"/usr/share/openrct2

	mv \
		title \
		object \
		"$pkgdir"/usr/share/openrct2
}

check() {
	cd build
	# test failures due to unable to select language
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest -E "(ride_ratings|multilaunch|tile_elements|pathfinding|s6importexporttests)"
}

data() {
	mkdir -p "$subpkgdir"/usr/share/openrct2

	mv \
		"$pkgdir"/usr/share/openrct2/object \
		"$pkgdir"/usr/share/openrct2/g2.dat \
		"$pkgdir"/usr/share/openrct2/shaders \
		"$pkgdir"/usr/share/openrct2/language \
		"$subpkgdir"/usr/share/openrct2
}

cli() {
	depends="openrct2-data"
	install="$subpkgname.post-install"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/openrct2-cli "$subpkgdir"/usr/bin/openrct2-cli
}
sha512sums="abe7c344b7588b169c95ffe0ab9028f72614d9b5783d81fa4f97f206d90d8cbaa0b91f04314c10926dbd5f68bba166558c428557f598abb343d306800611fb24  openrct2-v0.2.6.tar.gz
7592c5397ceb27347c127ae5c4f8e11d7ef2ff23c97f627b354f941894420f546ffdcff88e2348e42c82d182ccf620e739c745d894a9b5650a0d7d028b68a106  openrct2-0.2.6-title_sequences.zip
66e7a55ca894f2ea11af1c6300f934ef00f659137dded06f54bf749f490ff6063f95da800ae3cbfbbffe1c3e7d995e307d1281d57e4454ded6fed5affde84f8e  openrct2-0.2.6-objects.zip"
